package com.lwm.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import com.lwm.domain.InventoryApproval;
import com.lwm.domain.ResponseResult;
import com.lwm.dto.PageParams;
import com.lwm.service.InventoryApprovalService;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 入库申请表(InventoryApproval)表控制层
 *
 * @author lzl
 * @since 2023-10-17 13:05:00
 */
@RestController
@RequestMapping("inventoryApproval")
public class InventoryApprovalController {
    /**
     * 服务对象
     */
    @Resource
    private InventoryApprovalService inventoryApprovalService;

    /**
     * 分页查询
     *
     * @param inventoryApproval 筛选条件
     * @param pageParams       分页对象
     * @return 查询结果
     */
    @GetMapping("/page")
    public ResponseResult<PageInfo> queryByPage(InventoryApproval inventoryApproval, PageParams pageParams) {
        return inventoryApprovalService.queryByPage(inventoryApproval, pageParams);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseResult<InventoryApproval> queryById(@PathVariable("id") Long id) {
        return inventoryApprovalService.queryById(id);
    }

    /**
     * 新增数据
     *
     * @param inventoryApproval 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<InventoryApproval> add(InventoryApproval inventoryApproval) {
        return ResponseEntity.ok(this.inventoryApprovalService.insert(inventoryApproval));
    }

    /**
     * 编辑数据
     *
     * @param inventoryApproval 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseResult edit(@RequestBody InventoryApproval inventoryApproval) {
        return inventoryApprovalService.update(inventoryApproval);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.inventoryApprovalService.deleteById(id));
    }

}

